<template>
  <el-dialog :visible.sync="visible" :title="title" :close-on-click-modal="false">
    <el-form ref="dataFrom" :model="dataFrom" label-position="right" style="width: 500px;">
      <el-form-item prop="strategyMethod">
        <el-input v-model="dataFrom.strategyMethod" placeholder="请输入属性名称" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="addSubmit()">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addStrategyMethod, updateStrategyMethod } from '@/api/setting'

export default {
  data() {
    return {
      visible: false,
      title: '新增属性',
      dataFrom: {
        methodId: '',
        marketId: '',
        strategyMethod: '',
        type: ''
      }
    }
  },
  methods: {
    init(marketId, style, row) {
      this.visible = true
      this.$nextTick(() => {
        this.dataFrom = {
          methodId: '',
          marketId: '',
          strategyMethod: ''
        }
        this.dataFrom.marketId = marketId || null
        this.dataFrom.style = style || null
        if(row) {
          this.title = '修改属性'
          this.dataFrom.methodId = row.id
          this.dataFrom.strategyMethod = row.name
          this.dataFrom.type = row.type
        }
      })
    },
    addSubmit() {
      if(this.dataFrom.methodId) {
        updateStrategyMethod({ ...this.dataFrom }).then(res => {
          console.log('修改', res)
          // this.$notify({
          //   message: '修改成功', 
          //   type: 'success',
          //   duration: 2000
          // })
          this.$emit('openClose')
          this.visible = false
        })
      }else {
        addStrategyMethod({ ...this.dataFrom }).then(res => {
          console.log('新增', res)
          // this.$notify({
          //   message: '新增成功', 
          //   type: 'success',
          //   duration: 2000
          // })
          this.$emit('openClose')
          this.visible = false
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
